//
//  XMGLoginController.m
//  01.WeChat(EaseMobSDK导入)
//
//  Created by 肖剑 on 15/12/1.
//  Copyright © 2015年 肖剑. All rights reserved.
//

#import "XMGLoginController.h"
#import "UIViewExt.h"

#import "WSNavigationController.h"
#import "WSRecentMsgTableViewController.h"
#import "WSBuddyListViewController.h"

#define kWeChatScreenHeight [UIScreen mainScreen].bounds.size.height
#define kWeChatScreenWidth [UIScreen mainScreen].bounds.size.width

@interface XMGLoginController ()
@property(nonatomic,strong) UITabBarController *mainTabBar;

@end

@implementation XMGLoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 登陆标题
    self.title = @"登陆";
    
    // 账号标题
    UILabel *accLbl = [[UILabel alloc]init];
    accLbl.frame = CGRectMake(10, 80,80 , 44);
    accLbl.text = @"账号：";
    [self.view addSubview:accLbl];
    
    // 账号输入框
    UITextField *accField = [[UITextField alloc]init];
    accField.borderStyle = UITextBorderStyleRoundedRect;
    accField.frame = CGRectMake(accLbl.right, accLbl.top, kWeChatScreenWidth - 10 * 2 - accLbl.width, 44);
    [self.view addSubview:accField];
    
    // 密码标题
    UILabel *pswLbl = [[UILabel alloc]init];
    pswLbl.frame = CGRectMake(10, accLbl.bottom + 10,80 , 44);
    pswLbl.text = @"密码：";
    [self.view addSubview:pswLbl];
    
    
    // 密码输入框
    UITextField *pswField = [[UITextField alloc]init];
    pswField.borderStyle = UITextBorderStyleRoundedRect;
    pswField.frame = CGRectMake(accLbl.right, pswLbl.top, kWeChatScreenWidth - 10 * 2 - accLbl.width, 44);
    [self.view addSubview:pswField];
    
    // 登陆按钮
    CGFloat btnWidth = (kWeChatScreenWidth - 10 * 3)/2;
    UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    loginBtn.frame = CGRectMake(10, pswLbl.bottom + 10*3, btnWidth, 44);
    [loginBtn setBackgroundColor:[UIColor redColor]];
    [loginBtn setTitle:@"登陆" forState:UIControlStateNormal];
    [loginBtn addTarget:self action:@selector(loginBtnClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginBtn];
    
    // 注册按钮
    UIButton *registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    registerBtn.frame = CGRectMake(loginBtn.right + 10, loginBtn.top, btnWidth, 44);
    [registerBtn setBackgroundColor:[UIColor redColor]];
    [registerBtn setTitle:@"注册" forState:UIControlStateNormal];
     [registerBtn addTarget:self action:@selector(registerBtnClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registerBtn];
    
    
    


}

- (void)loginBtnClickAction{

    UIWindow * window = [UIApplication sharedApplication].windows.firstObject;
    window.rootViewController = [self mainTabBar] ;
}


- (void)registerBtnClickAction{
    
}


-(UITabBarController *)mainTabBar
{
    if (_mainTabBar) {
        return _mainTabBar;
    }
    
    _mainTabBar = [[UITabBarController alloc]init];
  
    WSRecentMsgTableViewController *message = [[WSRecentMsgTableViewController alloc]init];
    
    WSBuddyListViewController *tel = [[WSBuddyListViewController alloc]init];
        
    [_mainTabBar setViewControllers:@[[[WSNavigationController alloc]initWithRootViewController:message],[[WSNavigationController alloc]initWithRootViewController:tel]]];
    
    return _mainTabBar;
}






@end
